<template>
	  <view class="container">
	    <view class='margin' v-for='item in currentData' :key='item.id'>
	      <card :item='item' :hidden='true'></card>
	    </view>
		<view @click="toPublish()">
			发贴
		</view>
	  </view>
	  
</template>

<script>
	import card from "../../components/card.vue";
	export default {
		data() {
			return {
				currentData:[{
							"id": 52,
							"uid": "asd6a4w6d46aw46asd",
							"content": "谢邀，年薪百万，刚下飞机。",
							"tag": 18,
							"title": "时间管理达人52",
							"time": "2020-06-14T09:22:15.000+0000",
							"user": {
								"openId": "asd6a4w6d46aw46asd",
								"nickname": "测试昵称",
								"photo": "02d2ccf1178a4b63a99161ed54304988.jpg",
								"background": "ca9e40b604b14429b28e790b6e220517.jpg"
							},
							"pictures": [
								"c45ed91e35234078b64918739114fe7d.jpg",
								"f7e3339c150a462abdab0b68bdda5305.jpg",
								"f30a61e11fe048c2bd8bc43cb171a530.jpg"
							]
						}, {
							"id": 51,
							"uid": "asd6a4w6d46aw46asd",
							"content": "啊啊啊啊",
							"tag": 1,
							"title": "debug时间到",
							"time": "2020-06-14T09:08:50.000+0000",
							"user": {
								"openId": "asd6a4w6d46aw46asd",
								"nickname": "测试昵称",
								"photo": "02d2ccf1178a4b63a99161ed54304988.jpg",
								"background": "ca9e40b604b14429b28e790b6e220517.jpg"
							},
							"pictures": [
								"c45ed91e35234078b64918739114fe7d.jpg",
								"f7e3339c150a462abdab0b68bdda5305.jpg",
								"f30a61e11fe048c2bd8bc43cb171a530.jpg"
							]
						}, {
							"id": 50,
							"uid": "asd6a4w6d46aw46asd",
							"content": "1",
							"tag": 1,
							"title": "人才14",
							"time": "2020-06-14T09:07:31.000+0000",
							"user": {
								"openId": "asd6a4w6d46aw46asd",
								"nickname": "测试昵称",
								"photo": "02d2ccf1178a4b63a99161ed54304988.jpg",
								"background": "ca9e40b604b14429b28e790b6e220517.jpg"
							},
							"pictures": [
								"c45ed91e35234078b64918739114fe7d.jpg",
								"f7e3339c150a462abdab0b68bdda5305.jpg",
								"f30a61e11fe048c2bd8bc43cb171a530.jpg"
							]
						}, {
							"id": 49,
							"uid": "asd6a4w6d46aw46asd",
							"content": "啊啊啊啊",
							"tag": 1,
							"title": "debug时间到",
							"time": "2020-06-14T09:06:27.000+0000",
							"user": {
								"openId": "asd6a4w6d46aw46asd",
								"nickname": "测试昵称",
								"photo": "02d2ccf1178a4b63a99161ed54304988.jpg",
								"background": "ca9e40b604b14429b28e790b6e220517.jpg"
							},
							"pictures": [
								"c45ed91e35234078b64918739114fe7d.jpg",
								"f7e3339c150a462abdab0b68bdda5305.jpg",
								"f30a61e11fe048c2bd8bc43cb171a530.jpg"
							]
						}, {
							"id": 48,
							"uid": "asd6a4w6d46aw46asd",
							"content": "啊啊啊啊",
							"tag": 1,
							"title": "debug时间到",
							"time": "2020-06-14T09:06:01.000+0000",
							"user": {
								"openId": "asd6a4w6d46aw46asd",
								"nickname": "测试昵称",
								"photo": "02d2ccf1178a4b63a99161ed54304988.jpg",
								"background": "ca9e40b604b14429b28e790b6e220517.jpg"
							},
							"pictures": [
								"c45ed91e35234078b64918739114fe7d.jpg",
								"f7e3339c150a462abdab0b68bdda5305.jpg",
								"f30a61e11fe048c2bd8bc43cb171a530.jpg"
							]
						}
				]
			}
		},
		components: {
		    card
		 },
		methods: {
			//格式化时间
			 formatUTC(utc_datetime) {
			  // 转为正常的时间格式 年-月-日 时:分:秒
			  var T_pos = utc_datetime.indexOf('T');
			  var Z_pos = utc_datetime.indexOf('Z');
			  var year_month_day = utc_datetime.substr(0,T_pos);
			  var hour_minute_second = utc_datetime.substr(T_pos+1,Z_pos-T_pos-1);
			  var new_datetime = year_month_day+" "+hour_minute_second; // 2017-03-31 08:02:06
			
			  // 处理成为时间戳
			  timestamp = new Date(Date.parse(new_datetime));
			  timestamp = timestamp.getTime();
			  timestamp = timestamp/1000;
			
			  // 增加8个小时，北京时间比utc时间多八个时区
			  var timestamp = timestamp+8*60*60;
			
			  // 时间戳转为时间
			  var beijing_datetime = new Date(parseInt(timestamp) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
			  return beijing_datetime;
			} ,
			//切换到发贴页面
			toPublish(){
				uni.navigateTo({
				    url: './publish'
				});
			},
			//获取列表信息
			getForumList(){
				uni.request({
					url: this.$websiteUrl + "/forum",
					// data: {
					// 	page:2,
					// 	size:5
					// },
					header: {
						token: this.$getToken()
					},
					success: (res) => {
						console.log(res.data.data.datas);
						this.currentData = res.data.data.datas;
					}
				});
			}
			
		},
		onLoad() {
			this.getForumList();
		}
	}
</script>

<style>

</style>
